<#include "/common/layout_dl.html">
    <@header>
</@header>
<@body>
<form  role="form" action="/movie/upload" class="layui-form layui-form-pane pd10" method="post">
    <div class="box-body">
        <div class="form-group">
            <label for="title">标题:</label>
            <input type="text" id="title" name="title" class="form-control" lay-verify="required" placeholder="请输入标题">
        </div>
        <div class="form-group">
            <label for="headImg">封面图:</label>
            <input type="hidden" name="headImg" id="headImg" />
            <input type="file" class="file-loading" name="file" id="headImgFile"/>
        </div>
        <div class="form-group">
            <label for="movie">视频（必须为.mp4格式，最大50M）</label>
            <input type="hidden" name="movie" id="movie" />
            <input type="file" class="file-loading" name="file" id="movieFile"/>
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-success" lay-submit lay-filter="submit"><i class="fa fa-save"></i> 上传
            </button>
        </div>
    </div>
</form>
</@body>
<@footer>
</@footer>
<script src="/plugins/bootstrap-fileinput/js/fileinput.min.js"></script>
<script src="/plugins/bootstrap-fileinput/js/locales/zh.js"></script>
<script>
    //初始化fileinput控件（第一次初始化）
    function initFileInput(ctrlName, uploadUrl, allowdExt) {
        var control = $('#' + ctrlName);

        control.fileinput({
            deleteUrl: "/ftp/delete",
            language: 'zh', //设置语言
            uploadUrl: uploadUrl, //上传的地址
            allowedFileExtensions: allowdExt,//接收的文件后缀
            showUpload: false, //是否显示上传按钮
            showCaption: false,//是否显示标题
            browseClass: "btn btn-primary"
        });
    }

    initFileInput("headImgFile", "/ftp/upload", ['jpg', 'png','gif']);
    initFileInput("movieFile", "/ftp/upload", ['mp4']);

    //上传成功回调函数
    $('#headImgFile').on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        console.log(result.status);
        console.log(result.urls);
        $('#headImg').val(result.urls[0]);
    });

    //上传成功回调函数
    $('#movieFile').on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        console.log(result.status);
        console.log(result.urls);
        $('#movie').val(result.urls[0]);
    });

</script>